﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace YasharEl.Infrastructure.ServiceBus.Configuration
{
    public partial class UnicastBusConfig
    {
        private bool HandleUnrecognizedElement(string elementName, XmlReader reader)
        {
            #region Faults manager

            if (elementName == "faultForwarder")
            {
                FaultForwarderManagerConfig faultForwarder = new FaultForwarderManagerConfig();
                faultForwarder.DeserializeElement(reader);
                this.FaultManager = faultForwarder;
                return true;
            }

            if (elementName == "dbTransport")
            {
                DbTransportConfig db = new DbTransportConfig();
                db.DeserializeElement(reader);
                this.Transport = db;
                return true;
            }

            #endregion

            #region Transport

            if (elementName == "msmqTransport")
            {
                MsmqTransportConfig msmq = new MsmqTransportConfig();
                msmq.DeserializeElement(reader);
                this.Transport = msmq;
                return true;
            }

            if (elementName == "dbTransport")
            {
                DbTransportConfig db = new DbTransportConfig();
                db.DeserializeElement(reader);
                this.Transport = db;
                return true;
            }

            #endregion

            #region SubsriptionsStorage

            if (elementName == "msmqSubscriptionsStorage")
            {
                MsmqSubscriptionStorageConfig msmq = new MsmqSubscriptionStorageConfig();
                msmq.DeserializeElement(reader);
                this.SubscriptionStorage = msmq;
                return true;
            }

            if (elementName == "dbSubscriptionsStorage")
            {
                DbSubscriptionStorageConfig db = new DbSubscriptionStorageConfig();
                db.DeserializeElement(reader);
                this.SubscriptionStorage = db;
                return true;
            }

            #endregion

            #region Message Serializer

            if (elementName == "xmlMessageSerializer")
            {
                XmlMessageSerializerConfig xml = new XmlMessageSerializerConfig();
                xml.DeserializeElement(reader);
                this.MessageSerializer = xml;
                return true;
            }

            #endregion

            return false;
        }
    }
}
